// button.h
#ifndef BUTTON_H
#define BUTTON_H

#include <stddef.h>
#include "FreeRTOS.h"
#include "task.h"
#include "hw_gpio_defs.h"
#include "hw_gpio_hal.h"

#define BUTTON_SCAN_INTERVAL_MS         20UL
#define BUTTON_MAX_NUM                  4
#define BUTTON_DEBOUNCE_TICKS           3UL

typedef struct Button Button_t;

typedef enum {
    BUTTON_EVENT_CLICK = 0,
    BUTTON_EVENT_MAX
} ButtonEvent_t;

typedef void (*Button_Event_Callback)(Button_t* button);

// Button_t 结构体定义中移除了 volatile 关键字
struct Button {
    u32                         pin;
    u8                          pressed_level;
    const char*                 name;
    Button_Event_Callback       callbacks[BUTTON_EVENT_MAX];
    u8                          state;         // 移除 volatile
    u8                          debounce_cnt;  // 移除 volatile
};

int button_register(Button_t* button, u32 pin, u8 pressed_level, const char* name);
void Button_SetClickCallback(Button_t* button_instance, Button_Event_Callback on_click_cb);
Button_t* Button_GetByName(const char* name);
void button_process(void);

#endif // BUTTON_H
